#!/usr/bin/env python
# -*- coding:utf-8 -*-

# file:do_exam1.py
# author:王雯雯
# datetime:2024-12-7
# software: PyCharm
import requests
import threading
import time


def getHtmlText(url):
    try:
        r = requests.get(url, timeout=30)
        r.raise_for_status()
        r.encoding = r.apparent_encoding
        return r.text
    except:
        return "产生异常"


def check_url(url):
    result = getHtmlText(url)
    print(f"{url} 的访问情况: {result!= '产生异常'}")


if __name__ == "__main__":
    urls = []
    with open(r"D:\url_data.txt", "r") as file:
        for line in file.readlines():
            urls.append(line.strip())

    threads = []
    for url in urls:
        thread = threading.Thread(target=check_url, args=(url,))
        threads.append(thread)
        thread.start()

    for thread in threads:
        thread.join()